How to select the first occurring element after another element?
How to select the first occurring element after another element?
24621-Jul-2023
Updated on 21-Jul-2023
Home / DeveloperSection / Forums / How to select the first occurring element after another element?
How to select the first occurring element after another element?
Aryan Kumar
21-Jul-2023To select the first occurring element after another element, you can use the
+
selector in CSS. The+
selector matches an element that is immediately preceded by another element. For example, the following CSS will select the firstp
element that is immediately after anh1
element:CSS
Here is an example of how you can use the
+
selector to select the first occurring element after another element in HTML:HTML
The following CSS will set the color of the first
p
element after theh1
element to red:CSS
This will change the color of the first
p
element to red, but will not affect the otherp
elements.You can also use the
+
selector to select all of the elements that are immediately after another element. For example, the following CSS will select all of thep
elements that are immediately after anh1
element:CSS
Here is an example of how you can use the
+
selector to select all of the elements that are immediately after another element in HTML:HTML
This CSS will set the color of all of the
p
elements to red.